package com.anolesoft.twelvePlan.service.impl;

import com.anolesoft.twelvePlan.dto.BasWorkhourCountDTO;
import com.anolesoft.twelvePlan.entity.BasWorkhourCountDO;
import com.anolesoft.twelvePlan.mapper.BasWorkhourCountMapper;
import com.anolesoft.twelvePlan.service.BasWorkhourCountService;
import com.anolesoft.yr.util.CommonUtils;
import com.anolesoft.yr.util.PageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zyq
 * @date 2022/7/1
 */
@Service
@Slf4j
public class BasWorkhourCountServiceImpl implements BasWorkhourCountService {

    @Autowired
    private BasWorkhourCountMapper basWorkhourCountMapper;

    @Override
    public PageData<List<BasWorkhourCountDTO>> queryWorkHour(BasWorkhourCountDTO basWorkhourCountDTO, Integer pageNo, Integer pageSize) {
        Page<BasWorkhourCountDTO> page = new Page<>(pageNo,pageSize);
        List<BasWorkhourCountDTO> basWorkhourCountDTOS = this.basWorkhourCountMapper.queryWorkHour(BasWorkhourCountDO.builder()
                .gongzhong(CommonUtils.stringNull(basWorkhourCountDTO.getGongzhong()))
                .vDate(CommonUtils.stringNull(basWorkhourCountDTO.getVDate()))
                .factoryId(CommonUtils.stringNull(basWorkhourCountDTO.getFactoryId()))
                .build(), page);
        return new PageData<>(((int) page.getTotal()), basWorkhourCountDTOS);
    }
}
